package org.example.mrrope.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.mrrope.service.PurchaseReceivingService;
import org.example.mrrope.service.PurchaseRequisitionService;
import org.example.mrrope.service.WuLiaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "宜搭", tags = {"扩展接口"})
@RestController
@RequestMapping("/ext")
@Slf4j
public class ExtendController {

    @Autowired
    WuLiaoService wuLiaoService;
    @Autowired
    PurchaseRequisitionService purchaseRequisitionService;
    @Autowired
    PurchaseReceivingService purchaseReceivingService;

    @GetMapping("/saveBZ")
    @ApiOperation("查当前工人进行中工单")
    public String saveBZ(@RequestParam("uuid") String uuid){
        try {
            return wuLiaoService.saveWuLiaoWorkOrder(uuid).toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/refreshPurchase")
    @ApiOperation("刷新采购订单")
    public String refreshPurchaseOrder(@RequestParam("id") String id,@RequestParam("poId") String poId){
        try {
            purchaseRequisitionService.refreshPurchaseOrder(id,poId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "success";
    }

    @GetMapping("/restock")
    @ApiOperation("重新入库")
    public String restock(@RequestParam("poId") String poId,
                          @RequestParam("tabName") String tabName,
                          @RequestParam("groupId") Integer groupId){
        try {
            purchaseReceivingService.restock(poId,tabName,groupId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "success";
    }
}
